package com.lqd.demo.springboot.orm.jdbcTemplate.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import javax.annotation.Resource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import com.lqd.demo.springboot.orm.jdbcTemplate.bean.UserLoginLog;
/**
 * 注意 批量插入数据时要 绑定参数 通过预处理方式添加 性能更高
 * @author Mr.s
 *
 */
@Repository
public class UserLoginLogDao {

	@Resource
	private JdbcTemplate jdbcTemplate;
	
	public UserLoginLog getById(long id){
		String sql = "select * from t_e_user_login_test_log where id=?";
		//BeanPropertyRowMapper<UserLoginLog>(UserLoginLog.class);
		RowMapper<UserLoginLog> rowMapper = new UserLoginLogRowMapper();
		return jdbcTemplate.queryForObject(sql, rowMapper,id);
	}
	
}

class UserLoginLogRowMapper implements RowMapper<UserLoginLog> {

	@Override
	public UserLoginLog mapRow(ResultSet rs, int arg1) throws SQLException {
		UserLoginLog g =new UserLoginLog() ;
		g.setId(rs.getInt("id"));
		g.setUsername(rs.getString("username"));		
		return g;
	}
	
	
}